package com.mifengs.mall.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.CornerPathEffect;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mifengs.mall.R;
import com.mifengs.mall.entity.AdvertBean;
import com.mifengs.mall.util.ImageLoadUtil;

import java.util.List;

import static android.support.v4.content.ContextCompat.getColor;

/**
 * Created by lihaoqi on 2017/10/31.
 */

public class FourGridtemAdapter extends BaseQuickAdapter<AdvertBean,BaseViewHolder> {

    private Context mContext;

    public FourGridtemAdapter(@LayoutRes int layoutResId, @Nullable List<AdvertBean> data, Context mContext) {
        super(layoutResId, data);
        this.mContext = mContext;
    }

    @Override
    protected void convert(BaseViewHolder helper, AdvertBean item) {
        TextView discountText = helper.getView(R.id.pro_discount_text);
        ImageView imageView = helper.getView(R.id.iv_img);
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        TextView originalPrice = helper.getView(R.id.original_price_text);
        originalPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        originalPrice.getPaint().setAntiAlias(true);
        LinearLayout lLayout_price = helper.getView(R.id.lLayout_price);
        lLayout_price.setBackgroundColor(mContext.getResources().getColor(R.color.yellow));
//        int strokeWidth = 5; // 3dp 边框宽度
        int roundRadius = 8; // 8dp 圆角半径
//        int strokeColor = Color.parseColor("#2E3135");//边框颜色
        float elevation = 4.0f;
        int fillColor = Color.parseColor(item.getColor());//内部填充颜色
        GradientDrawable gd = new GradientDrawable();
        gd.setColor(fillColor);
//        gd.setCornerRadius(roundRadius);
        gd.setCornerRadii(new float[] {0,0,0,0,10,10,10,10,});
//        gd.setStroke(strokeWidth, strokeColor);
        lLayout_price.setBackground(gd);
//        lLayout_price.setElevation(elevation);
        if(item.getDiscountText().equals("")){
            discountText.setVisibility(View.GONE);
        }else{
            discountText.setVisibility(View.VISIBLE);
        }
        helper.setText(R.id.pro_discount_text,item.getDiscountText()).setText(R.id.normal_price_text,"¥ "+item.getPrice()).setText(R.id.original_price_text,"¥ "+item.getCashwtf());
        ImageLoadUtil.displayImage(mContext,item.getImg(),imageView);
    }

}